package com.chart.web.controller.chart;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chart.chart.domian.vo.ChartViewsThemeVO;
import com.chart.chart.domian.vo.ChartViewsUserVO;
import com.chart.chart.service.IChartViewsThemeService;
import com.chart.common.core.domain.AjaxResult;
import com.example.entity.ChartViewsTheme;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("views/theme")
public class ChartViewsThemeController {


    @Autowired
    private IChartViewsThemeService chartViewsThemeService;


    @GetMapping("queryViewsThemes")
    public AjaxResult queryViewsThemes() {
        // 使用 LambdaQueryWrapper 按 sort 字段排序
        LambdaQueryWrapper<ChartViewsTheme> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByAsc(ChartViewsTheme::getSort); // 按 sort 字段升序排序
        // 获取排序后的主题列表
        List<ChartViewsTheme> list = chartViewsThemeService.list(queryWrapper);

        // 转换为 VO 对象
        ArrayList<ChartViewsThemeVO> chartViewsUserVOS = new ArrayList<>();
        for (ChartViewsTheme chartViewsTheme : list) {
            ChartViewsThemeVO chartViewsThemeVO = new ChartViewsThemeVO();
            BeanUtils.copyProperties(chartViewsTheme, chartViewsThemeVO);
            chartViewsUserVOS.add(chartViewsThemeVO);
        }

        return AjaxResult.success(chartViewsUserVOS);
    }














}
